module("NCPanel", package.seeall )

/* ==============================
	Choose team panel
   ============================ */
   
   
local function GetTeamForm( parent )
	
	local Form = vgui.Create( "DForm", parent )
	Form:SetWide( 250 )
	Form:SetName("Choose team")
	
	for _, teamId in pairs( Team.List ) do
	
		local button = Form:Button( team.GetName( teamId ) )
		
		button.DoClick = function() 
			RunConsoleCommand( "changeteam", teamId ) 
		end
		button.GetDisabled = function()
			return teamId == LocalPlayer():Team()
		end
	
	end

	Form:InvalidateLayout( true )
	return Form
end

local function GetClassForm( parent )
	
	local Form = vgui.Create( "DForm", parent )
	Form:SetWide( 200 )
	Form:SetName("Choose class")
	
	for _, class in pairs( Class.List ) do
	
		local button = Form:Button( class.Name or "Unknown" )
		
		button.DoClick = function() 
			RunConsoleCommand( "nc_class", class.Id ) 
		end
		button.GetDisabled = function()
			return class.Id == LocalPlayer():GetInfoNum("nc_class")
		end
	
	end

	Form:InvalidateLayout( true )
	return Form
end

TeamPanel = nil

function OpenTeamPanel()

	CloseTeamPanel()
	
	TeamPanel = vgui.Create( "DFrame" )
	TeamPanel:SetTitle( "NC: Source Forts" )
	TeamPanel:SetVisible( true )
	TeamPanel:SetDraggable( true )
	TeamPanel:ShowCloseButton( true )
	TeamPanel:MakePopup()
	
	local TeamForm = GetTeamForm( TeamPanel )
	local ClassForm = GetClassForm( TeamPanel )
	
	TeamForm:SetPos( 5, 27 )
	ClassForm:SetPos( 5 + TeamForm:GetWide() + 10, 27 )
	
	
	TeamPanel:SetSize( ClassForm.x + ClassForm:GetWide() + 10, math.max( TeamForm:GetTall(), ClassForm:GetTall() ) + 27 + 5 )
	TeamPanel:Center()

end 

function CloseTeamPanel()

	if ValidPanel( TeamPanel ) then
		TeamPanel:Remove()
		TeamPanel = nil
	end

end 

/*---------------------------------------------------------
   Name: gamemode:ShowTeam( )
   Desc: 
---------------------------------------------------------*/
function GM:ShowTeam()
	OpenTeamPanel()
end

/*---------------------------------------------------------
   Name: gamemode:HideTeam( )
   Desc: 
---------------------------------------------------------*/
function GM:HideTeam()
	CloseTeamPanel()
end